package com.masterclient.app.businessmodule.minemodule.point.adapter;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.LinearLayout;

import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.eoner.baselibrary.utils.ScreenUtils;
import com.eoner.baselibrary.utils.ViewTransformUtil;
import com.masterclient.app.R;
import com.masterclient.app.businessmodule.minemodule.point.model.PointMainListBean;
import com.masterclient.app.utils.CommonUtil;

/**
 * @auther hjian
 * @date 2020/7/2.
 */
public class PointEarnAdapter extends BaseQuickAdapter<PointMainListBean, BaseViewHolder> {

    public PointEarnAdapter() {
        super(R.layout.item_gold_earn);
    }

    @Override
    protected void convert(BaseViewHolder helper, PointMainListBean item) {

        ViewTransformUtil.glideImageView(mContext, item.getGroup_image(), helper.getView(R.id.item_gold_earn_img), new CenterCrop(),
                R.mipmap.user_head_default_icon0);
        RecyclerView recyclerView = helper.getView(R.id.item_gold_earn_recycler);

        PointEarnChildAdapter earnAdapter = new PointEarnChildAdapter();
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext, LinearLayout.HORIZONTAL, false));
        recyclerView.setAdapter(earnAdapter);
        earnAdapter.bindToRecyclerView(recyclerView);
        int width = ScreenUtils.getScreenWidth() - ScreenUtils.dp2px(86);
        earnAdapter.setWidth(item.getAd_list().size()>3?(int)(width/3.3f):width/item.getAd_list().size());
        earnAdapter.setNewData(item.getAd_list());

        earnAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                CommonUtil.goAnyWhere(mContext,item.getAd_list().get(position).getTarget(),item.getAd_list().
                        get(position).getTarget_id(),"","","");
            }
        });
    }

}
